<?php use_javascript('jquery-1.3.2.min.js') ?>
<?php use_helper ('Form','Javascript','Object') ?>

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="heading_table">
    <tr>
        <td height="30"><span class="heading">List of Occupant in Buildings</span></td>
        <td align="right" height="30" valign="bottom">
        <span style="float:right"><?php echo image_tag('icon_addRight.jpg', 'width="2"', 'height="22"')?></span>
        <?php echo link_to('Add New Occupant', 'Occupant/add', array('class'=>'addNew')) ;?>
        </td>
    </tr>
</table> 
 

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="datagrid">
    <tr>
        <!--<th width="8%" style="text-align:left;">Station</th>-->
        <th width="25%" style="text-align:left;">Building Name</th>
        <th width="11%" style="text-align:left;">Cosmr No.</th>
        <th width="10%" style="text-align:left;">Army No.</th>
        <th width="25%" style="text-align:left;">Rank/Name</th>
        <th width="16%" style="text-align:left;">Unit/Formation</th>
        <!--<th style="text-align:left;">Last Updated</th>-->
        <th width="13%" style="text-align:left;">Operation</th>
    </tr>

<!-- Populating the List -->
	<?php 
    if (count($occupants)): ?>
    <?php $previous = "";?>
	<?php foreach ($occupants as $j => $occupant) : ?>
    
    <?php $current = $occupant->getStation(); ?>
        <?php if ($current != $previous): ?>
        <tr>
            <td colspan="7" class="subhdng">
            <strong><?php echo $current ;?></strong>
            </td>
        </tr>
    <?php endif; ?>
  
    <tr>
        <!--<td align="left">&nbsp;</td>-->
        <td align="left"><?php echo $occupant->getBuilding(); ?> </td>
        <td style="text-align:left;"><?php echo $occupant->getBuilding()->getConsumerNo(); ?> </td>
        <td align="left">&nbsp;<?php echo $occupant->getArmyNo(); ?></td>
        <td align="left">&nbsp;<?php echo $occupant->getRank().' '. $occupant->getName(); ?></td>
        <td align="left">&nbsp;<?php echo $occupant->getUnit(); ?></td>
        <td align="right" class="edit">
        <?php echo link_to('&nbsp;','Occupant/edit?id='.Utility::EncryptQueryString($occupant->getId()),array('title'=>'Edit', 'class' => 'edit'))?>
        <?php echo link_to('&nbsp;','Occupant/delete?id='.Utility::EncryptQueryString($occupant->getId()), array('confirm'=>'Are you sure you want to Delete this?', 'title'=>'Delete', 'class' => 'delete')); ?>
        <?php if($occupant->getOccupiedStatus() == Constant::BUILDING_OCCUPIED)echo '&nbsp;'.link_to('Vacate','Occupant/vacateBuilding?id='.Utility::EncryptQueryString($occupant->getId()),array('title'=>'Vacate Building'))?>
        </td>
    </tr>

	<?php $previous = $current;?>
	<?php endforeach; ?>
        <tr>
            <td class="last">&nbsp;</td>
        </tr>
    <?php else:?>

    <tr>
        <td colspan="6" style="background:none; text-align:center;"><?php echo 'All buildings are <strong>Vacant</strong>. There is no Occupant in any Building.'; ?></td>
    </tr>
    
    <?php endif; ?>
</table>